home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Programming / Programming Languages / Yerk 3.64 / Asm source / Parser < prev    next >
Text File  |  1986-03-19  |  3KB  |  149 lines

  1. \ Assembler            ReeseWarner            3/85
  2. \  03/06/86  GDC  fixed MOVEM
  3. \  03/07/86  GDC  fixed displacement
  4.  
  5. \ KEY for TOKENTYPES
  6.  
  7. \ 1 - number
  8. \ 2 - word
  9. \ 3 - special
  10. \ 4 - EOL
  11.  
  12. 0 -> dlevel
  13.  
  14. 3 4 2darray next.state
  15. 3 4 2darray action
  16.  
  17. scon specials ",.\#/=]["
  18.  
  19. 0 value pos           \ position on line
  20. 0 value tiblen        \ length of line
  21.  
  22. 0 value linect
  23.  
  24. 0 value storedToken
  25.  
  26. 0 value charCount     \ char in definition
  27.  
  28. String token
  29.  
  30. 5 x-array actions
  31.  
  32. \ all action handlers for the action table
  33. ( char -- tokentype T or F )
  34. : act0
  35.     +: token 1 ++> pos
  36.     FALSE
  37. ;
  38. 'c act0 0 to: actions
  39.  
  40. : act1
  41.     drop
  42.     1 TRUE
  43. ;
  44. 'c act1 1 to: actions
  45.  
  46. : act2
  47.     +: token
  48.     1 ++> pos
  49.     3 TRUE
  50. ;
  51. 'c act2 2 to: actions
  52.  
  53. : act3
  54.     drop
  55.     2 TRUE
  56. ;
  57. 'c act3 3 to: actions
  58.  
  59. : act4
  60.     drop
  61.     1 ++> pos
  62.     FALSE
  63. ;
  64. 'c act4 4 to: actions
  65.  
  66. \ is char in the specials?
  67. : isSpec    { char secchar \ bool slen saddr -- bool }
  68.     false -> bool
  69.     specials -> slen -> saddr
  70.     slen 0
  71.     DO
  72.         saddr i + c@ char =
  73.         IF
  74.             true -> bool leave
  75.         THEN
  76.     LOOP
  77.     char ascii - = secchar ascii D = secchar ascii A =  \ for MOVEM
  78.                    secchar ascii d = secchar ascii a =
  79.                    or or or and
  80.     IF
  81.         true -> bool
  82.     THEN
  83.     bool
  84. ;
  85.  
  86. \  determine character class
  87. : charClass { char secchar -- class }
  88.     char secchar isSpec
  89.     IF
  90.         2                               \ special char
  91.     ELSE
  92.         char
  93.         CASE
  94.             $ 41 $ 5A RANGEOF 0 ENDOF   \ A to Z
  95.             $ 61 $ 7A RANGEOF 0 ENDOF   \ a to z
  96.             $ 30 $ 39 RANGEOF 1 ENDOF   \ 0 to 9
  97.             $ 24           OF 1 ENDOF   \ $
  98.             $  0 $ 20 RANGEOF 3 ENDOF   \ control char
  99.             0 swap
  100.         ENDCASE
  101.         char $ 2D = secchar $ 28 <> and IF drop 1 THEN
  102.     THEN
  103. ;
  104.  
  105. : getLine   { \ #chars -- }
  106. \   13 word
  107.     msg" getLine called"
  108.     query: topfile abort" Premature end of file"
  109.     bytesread: [ last: loadFile ] val" #chars read=" -> #chars
  110.     #chars ++> charCount
  111.     0 -> pos #chars -> tiblen
  112.     1 ++> linect
  113. ;
  114.  
  115. \ NextToken puts the token into string Token and returns one of the following
  116. \  four token types:
  117. \        number, word, special, end-of-line
  118. : nextToken     { \ curState nextChar secchar actNum theClass -- tokentype }
  119.   0 -> curState
  120.   clear: token
  121.   storedToken 0=
  122.   IF
  123.     BEGIN
  124.         pos tiblen =
  125.         IF
  126.             getLine
  127.             curState 0=
  128.             IF
  129.                 eol TRUE
  130.             ELSE
  131.                 eol -> storedToken
  132.                 curState TRUE
  133.             THEN
  134.         ELSE
  135.             tib pos + dup c@ -> nextChar   \ get next char
  136.             1+ c@ -> secchar
  137.             nextChar secchar charClass -> theClass
  138.             curState theClass at: action -> actNum
  139.             curState theClass at: next.state -> curState
  140.             nextChar actNum exec: actions
  141.         THEN
  142.     UNTIL
  143.   ELSE
  144.     storedToken
  145.     0 -> storedToken
  146.   THEN
  147.   uc: token 2drop
  148. ;
  149.